<?php
include("../te.php");

$te = new TE();
$te->parseFromFile("table_example.tpl.html");


$wt=$lt=0;
$total=1000;
$current=1;
$w=0;
$data=array();

for($i=1;$i<201;$i++) {
	if($total<1) break;
	
	
	$rand = rand(1,100);
	
	$current = neov($w,$current,$total);
	
	if($rand>60){ $w=1;}else{$w=0;}
	
	
	
	if($w==1){ $wt++; $total+=$current*2;} else { $lt++; $total=$total-$current;}
	
	
	$data[$i]=array($rand,$w,$current,$total);
	//echo "<pre>";
	//echo "$i) $rand : $w :: $current  / $total";
}
echo " \nTotal: $wt - $lt /$i :: $total";


function martingala($w,$current,$total){
	if($w==0 ){
		return $current*2;
	}
	else return 1;
}

function cangrejo($w,$current,$total){
	if($w==0 ){
		return $current*2;
	}
	else return ($current>1?$current/2:1);
}


function neov($w,$current,$total){
	if($w==0 ){
		
		return 1;
	}
	else return ($current>1?$current/2:($total>2*16?32:8 ));
}

//$te->grid->data  = $data;
//$te->grid->titles = array("rand","w","current","total");
$orow="";
foreach($data as $key=>$item){
$te->row->rand   = $item[0];
$te->row->w      = ($item[1]==1?"Gana":"Pierde");
$te->row->current= $item[2];
$te->row->total  = $item[3];
$orow.=$te->row->replace();
}
$te->row->block = $orow;
$te->row->replace();

echo $te->replace();

?>